package top.fyr.config;

import com.weibo.api.motan.config.springsupport.AnnotationBean;
import com.weibo.api.motan.config.springsupport.BasicRefererConfigBean;
import com.weibo.api.motan.config.springsupport.ProtocolConfigBean;
import com.weibo.api.motan.config.springsupport.RegistryConfigBean;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * @author fyr
 * @date 2018/3/15
 */
@SpringBootConfiguration
public class Config {

	/**
	 * 声明Annotation用来指定需要解析的包名
	 *
	 * @return
	 */
	@Bean
	public AnnotationBean motanAnnotationBean() {
		AnnotationBean motanAnnotationBean = new AnnotationBean();
		motanAnnotationBean.setPackage("top.fyr.controller");
		return motanAnnotationBean;
	}

	@Bean(name = "demoMotanClient")
	public ProtocolConfigBean protocolConfig2() {
		ProtocolConfigBean config = new ProtocolConfigBean();
		config.setDefault(true);
		config.setName("motan");
		config.setMaxContentLength(1048576);
		return config;
	}

	@Bean(name = "registry")
	public RegistryConfigBean registryConfig() {
		RegistryConfigBean config = new RegistryConfigBean();
		config.setRegProtocol("local");
		return config;
	}

	@Bean(name = "motantestClientBasicConfig")
	public BasicRefererConfigBean baseRefererConfig() {
		BasicRefererConfigBean config = new BasicRefererConfigBean();
		config.setProtocol("demoMotanClient");
		config.setGroup("motan-demo-rpc");
		config.setModule("motan-demo-rpc");
		config.setApplication("myMotanDemo");
		config.setRegistry("registry");
		config.setCheck(false);
		config.setAccessLog(true);
		config.setRetries(2);
		config.setThrowException(true);
		return config;
	}
}
